/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Utilities
*        文件名:             ResourceManagerWrapper.cs
*        创建系统时间:       2012/11/2 19:07:08
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.Utilities
{
    using System.Collections;

    public class ResourceManagerWrapper
    {
        private static volatile ResourceManagerWrapper instance = null;
        private static object locker = new object();
        private ECP.Utilities.ResourceManager ResourceManager;

        public string Get(string key)
        {
            return this.ResourceManager.Get(BaseSystemInfo.CurrentLanguage, key);
        }

        public string Get(BaseUserInfo userInfo, string key)
        {
            if ((userInfo != null) && !string.IsNullOrEmpty(userInfo.CurrentLanguage))
            {
                return this.ResourceManager.Get(userInfo.CurrentLanguage, key);
            }
            return this.ResourceManager.Get(BaseSystemInfo.CurrentLanguage, key);
        }

        public Hashtable GetLanguages()
        {
            return this.ResourceManager.GetLanguages();
        }

        public Hashtable GetLanguages(string path)
        {
            return this.ResourceManager.GetLanguages(path);
        }

        public Resources GetResources(string language)
        {
            return this.ResourceManager.LanguageResources[language];
        }

        public Resources GetResources(string path, string language)
        {
            string filePath = path + @"\" + language + ".xml";
            return this.ResourceManager.GetResources(filePath);
        }

        public void LoadResources(string path)
        {
            this.ResourceManager = ECP.Utilities.ResourceManager.Instance;
            this.ResourceManager.Init(path);
        }

        public void Serialize(string path, string language, string key, string value)
        {
            Resources resources = this.GetResources(path, language);
            resources.Set(key, value);
            string filePath = path + @"\" + language + ".xml";
            this.ResourceManager.Serialize(resources, filePath);
        }

        public static ResourceManagerWrapper Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (locker)
                    {
                        if (instance == null)
                        {
                            instance = new ResourceManagerWrapper();
                        }
                    }
                }
                return instance;
            }
        }
    }
}